import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

import Vant from 'vant';
import 'vant/lib/index.css';

import element from 'element-plus'


import 'element-plus/theme-chalk/index.css';

import axios from 'axios'
axios.defaults.baseURL = "http://127.0.0.1:8000/"

axios.prototype = axios

// createApp(App).use(store).use(router).mount("#app");
const app = createApp(App)

app.use(router);

app.use(store)

app.mount('#app')

app.use(Vant);

app.use(element)





router.beforeEach((to,from,next)=>{
    let white = ["/mylogin"]
    let pathlist = JSON.parse(localStorage.getItem('url1'))
    if(pathlist){
        for(var i=0;i<=pathlist.length;i++){
            white.push(pathlist[i])
        }
        if(white.includes(to.path)){
            next()
        }else{
            alert('没有权限')
        }
    }else{
        if(white.includes(to.path)){
            next()
        }else{
            alert('没有权限')
        }

    }
})

//拦截器

axios.interceptors.request.use(config=>{
    let token = localStorage.get(token)
    if(token){
        config.headers.Authorization = token
    }
    return config
},eror=>{
    router.push("/mylogin")
    return Promise.reject(error)
})






